<script>
import axios from "axios";
import {getToken} from "@/store/token";

export default {
  props: ["salesOrders"],
  data() {
    return {
      salesOrder: {
        orderId: "",
        returnTotal: 0,
        status: "",
        refuseCause: "",
      },
      visible: true,
      rules: {
        status: [
          {required: true, message: '请选择结果', trigger: 'blur'},
        ],
        refuseCause: [
          {required: true, message: '请输入拒绝原因', trigger: 'blur'},
        ]
      }
    }
  },
  methods: {
    submitSalesForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.salesOrder.orderId = this.salesOrders.orderId
          this.salesOrder.userId = this.salesOrders.userId
          this.$api.afterSale.updateAfterSales(this.salesOrder).then((res) => {
            var data = res.data;
            if (data.success) {
              this.$message.success("处理成功")
              this.$refs[formName].resetFields();
              this.visible = false
            } else {
              this.$message.error(data.message);
            }
          }).catch((resp) => {
            this.$message.error('服务器访问失败' + resp);
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    }, cancelSalesSubmit(formName) {
      this.$refs[formName].resetFields();
      this.visible = false
    },
  }, watch: {
    visible() {
      this.$emit('changeVal', this.visible)
    }
  }
}

</script>

<template>
  <el-dialog title="订单退款处理" :visible.sync="visible">
    <el-form :model="salesOrder" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
      <el-form-item label="订单id">
        <el-input readonly v-model="salesOrders.orderId"></el-input>
      </el-form-item>
      <el-form-item label="应退款金额">
        <el-input readonly v-model="salesOrders.returnTotal"></el-input>
      </el-form-item>
      <el-form-item label="退款原因">
        <el-input readonly v-model="salesOrders.returnCause"></el-input>
      </el-form-item>
      <el-form-item label="是否同意退款" prop="status">
        <el-select v-model="salesOrder.status" placeholder="请选择">
          <el-option value="7" label="同意"></el-option>
          <el-option value="8" label="拒绝"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item v-if="salesOrder.status==='8'" label="不同意理由" prop="refuseCause">
        <el-input v-model="salesOrder.refuseCause" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitSalesForm('ruleForm')">确定</el-button>
        <el-button @click="cancelSalesSubmit('ruleForm')">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<style scoped>

</style>